<template>
  <div class="app-container">
    <el-card>
      <h4>面试邀请</h4>
      <el-form ref="form" :model="form" label-width="100px">
        <el-row :gutter="10" type="flex">
          <el-form-item label="面试职位:">
            <el-select
              v-model="interviewQuery.jobid"
              placeholder=""
              @change="interviewYqChange"
            >
              <el-option
                v-for="item in positionLists"
                :key="item.id"
                :label="item.jobname"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="发送时间">
            <el-select
              v-model="interviewQuery.settr"
              placeholder=""
              @change="sendingTimeChange"
            >
              <el-option
                v-for="item in sendingTime"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-row>
      </el-form>
      <el-table :data="interviewListArray" style="width: 100%">
        <el-table-column prop="fullname" label="基本信息" width="300">
          <template slot-scope="scope">
            <div style="display: flex">
              <div class="portraitImg">
                <img
                  :src="
                    scope.row.photoImg === 0
                      ? scope.row.photoImgSrc
                      : 'https://blwcompany.nbblmc.cn' + scope.row.photoImgSrc
                  "
                  alt=""
                />
              </div>
              <div style="margin-left: 10px">
                <div>
                  <div style="color: #409eff">{{ scope.row.fullname }}</div>
                </div>
                <div>
                  {{ scope.row.age }}岁 | {{ scope.row.educationText }} |
                  {{ scope.row.experienceText }}经验 |
                  {{ scope.row.sexText }}
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="jobname"
          label="面试职位"
          width="width"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="prop"
          label="面试时间"
          width="width"
          align="center"
        >
          <template slot-scope="scope">
            {{ scope.row.interviewTime | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column
          prop="prop"
          label="操作状态"
          width="width"
          align="center"
        >
          <template slot-scope="scope">
            <el-tag :type="scope.row.isLook ? 'primary' : 'warning'">{{
              scope.row.isLook ? "已查看" : "未查看"
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="prop" label="操作" width="width" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              @click="detailClick(scope.row)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-row :gutter="10" style="margin-top: 20px" type="flex" justify="end">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[10, 20, 30, 50]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </el-row>
    </el-card>

    <!-- 面试详情 -->
    <el-dialog
      title="面试详情"
      :visible.sync="detailDialog"
      width="500px"
      custom-class="interview-details-dialog"
    >
      <div class="interview-details">
        <div class="info-item">
          <span class="label">面试形式：</span>
          <span class="value">面试邀请</span>
        </div>

        <div class="info-item">
          <span class="label">面试职位：</span>
          <span class="value">测试</span>
        </div>

        <div class="info-item">
          <span class="label">公司名称：</span>
          <span class="value">宁波市北仑区传媒中心</span>
        </div>

        <div class="info-item">
          <span class="label">面试时间：</span>
          <span class="value">{{
            interviewForm.interviewTime | dateFormat
          }}</span>
        </div>

        <div class="info-item">
          <span class="label">公司地址：</span>
          <span class="value">{{ interviewForm.address }}</span>
        </div>

        <div class="info-item">
          <span class="label">联系电话：</span>
          <span class="value">
            <el-link type="primary">{{ interviewForm.tel }}</el-link>
            ({{ interviewForm.contact }})
          </span>
        </div>

        <div class="info-item">
          <span class="label">备注：</span>
          <span class="value remarks"></span>
        </div>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="detailDialog = false">确定</el-button>
        <el-button @click="detailDialog = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { interviewListApi, selCompanyContentListApi } from "@/api/jlManage";
import { positionListApi } from "@/api/position";
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      // 面试邀请请求
      interviewQuery: {
        comid: "",
        page: 1,
        pageSize: 10,
        jobid: "",
        settr: "",
      },
      // 职位列表请求参数
      positionQuery: {
        audit: 1,
        page1: 1,
        pageSize: 10,
        uid: "",
      },
      // 面试邀请表单
      interviewForm: {},
      detailDialog: false,
      interviewListArray: [],
      positionLists: [],
      // 发送时间
      sendingTime: [
        { value: "", label: "不限" },
        { value: 3, label: "3天内" },
        { value: 7, label: "7天内" },
        { value: 15, label: "15天内" },
        { value: 30, label: "30天内" },
      ],
    };
  },
  created() {
    this.interviewQuery.comid = this.cid;
    this.positionQuery.uid = this.userId;
    this.interviewList();
    this.positionList();
  },
  computed: {
    ...mapGetters(["userId", "cid"]),
  },
  methods: {
    // 面试邀请职位改变
    interviewYqChange(val) {
      console.log(val);
      this.interviewList();
    },
    // 发送时间改变
    sendingTimeChange(val) {
      console.log(val);
      this.interviewList();
    },
    // 职位列表
    async positionList() {
      const res = await positionListApi(this.positionQuery);
      this.positionLists = res.records;
    },
    // 面试邀请页码改变
    handleSizeChange(pageSize) {
      this.interviewQuery.pageSize = pageSize;
      this.interviewList();
    },
    // 面试邀请点击页数改变
    handleCurrentChange(page) {
      this.interviewQuery.page = page;
      this.interviewList();
    },
    // 面试邀请列表
    async interviewList() {
      const res = await interviewListApi(this.interviewQuery);
      this.interviewListArray = res.records;
      this.total = res.total;
    },
    detailClick(row) {
      this.detailDialog = true;
      console.log(row);
      this.interviewForm = row;
    },
  },
};
</script>

<style lang="scss" scoped>
.imgBox {
  width: 52px;
  height: 52px;
  img {
    width: 100%;
    height: 100%;
  }
}

.interview-details-dialog {
  :deep(.el-dialog__header) {
    padding: 15px 20px;
    border-bottom: 1px solid #ebeef5;
    margin: 0;
  }

  :deep(.el-dialog__body) {
    padding: 20px;
  }

  :deep(.el-dialog__footer) {
    padding: 15px 20px;
    border-top: 1px solid #ebeef5;
    text-align: center;
  }
}

.interview-details {
  .info-item {
    margin-bottom: 16px;
    line-height: 20px;
    display: flex;

    &:last-child {
      margin-bottom: 0;
    }

    .label {
      width: 84px;
      color: #909399;
      flex-shrink: 0;
    }

    .value {
      color: #303133;
      flex: 1;
    }

    .remarks {
      color: #c0c4cc;
      font-style: italic;
    }
  }
}

.dialog-footer {
  .el-button {
    width: 90px;

    & + .el-button {
      margin-left: 12px;
    }
  }
}

.portraitImg {
  img {
    border-radius: 50%;
    width: 52px;
    height: 52px;
  }
}
</style>
